﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
public partial class LoginAlready : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //Session["UserID"] = Guid.NewGuid();

    }

   

    private DataSet GetUserLoginDataSet(string Email_Id, string Regstration_Id)
    {
        DataSet objDs=null;
        try
        {
            objDs = new UserMasterBAL().GetUserLogin(Email_Id, Regstration_Id);
            
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    protected void cmdLogin_Click(object sender, EventArgs e)
    {
        string UserEmailid = txtEmailID.Text.Trim();
        string UserRegID = txtRegid.Text.Trim();
        DataSet objDs = new DataSet();
        string EmailId = string.Empty;
        string RegstrationId = string.Empty;
        string strUserID = string.Empty;
        string strCandidateID = string.Empty;
        Session["CandidateUser"] = UserEmailid;
        objDs =    GetUserLoginDataSet(UserEmailid, UserRegID);

        if (objDs.Tables.Count > 0)
        {
            if(objDs.Tables[0].Rows.Count > 0)
            { 
                EmailId = Convert.ToString(objDs.Tables[0].Rows[0]["UserName"]);
                RegstrationId = Convert.ToString(objDs.Tables[0].Rows[0]["RegistrationNo"]);
                strUserID = Convert.ToString(objDs.Tables[0].Rows[0]["UserId"]);
                strCandidateID = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateID"]);

                if (EmailId == UserEmailid && RegstrationId == UserRegID)
                {
                    //session for pass below page.
                    Session["CandidateUserID"] = strUserID.Trim();
                    Session["CandidateID"] = strCandidateID.Trim();
                    Response.Redirect("~/Common/RegisterAlready.aspx");
                    
                }
                else
                {
                    lblErrorMsg.Text = "Invalid Email ID and Registration No.";
                    lblErrorMsg.ForeColor = System.Drawing.Color.Red;
                }

            }
            else
            {
                lblErrorMsg.Text = "Invalid Email ID and Registration No.";
                lblErrorMsg.ForeColor = System.Drawing.Color.Red;
                return;
            }

        }
        else
        {
            lblErrorMsg.Text = "Invalid Email ID and Registration No.";
            lblErrorMsg.ForeColor = System.Drawing.Color.Red;
            return;
        }


      
    }
    //protected void cmdCancel_Click(object sender, EventArgs e)
    //{
    //    Response.Redirect("../Login.aspx");
    //}
}